package cn.kgc.springboot.service.impl;

import cn.kgc.springboot.entity.User;
import cn.kgc.springboot.mapper.UserMapper;
import cn.kgc.springboot.response.ResponseResult;
import cn.kgc.springboot.service.UserService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author 课工场
 * @date 2024/8/15
 * @description
 */
@Service
public class UserServiceImpl implements UserService {

    @Resource
    private UserMapper userMapper;

    @Override
    public ResponseResult userPage(Integer page, Integer limit) {

        PageHelper.startPage(page,limit);
        List<User> users =  userMapper.selectUsers();
        long total = new PageInfo<User>(users).getTotal();

        ResponseResult responseResult = new ResponseResult();
        responseResult.setCode(0);
        responseResult.setData(users);
        responseResult.setCount(total);

        return responseResult;
    }
}
